package com.cmb.lk50.controller;

import com.cmb.lk50.common.AccessLog;
import com.cmb.lk50.common.extractor.BodyParamExtractor;
import com.cmb.lk50.common.extractor.UrlParamExtractor;
import com.cmb.lk50.common.receiver.ResponseBodyReceiver;
import org.json.JSONObject;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Mono;

import java.util.Map;

/**
 * Author       : 蒋俊钊 80256973
 * Date         : 2020/7/17
 * Copyright    (C) ChinaMerchantsBank
 */
@RestController
public class ReactorController {

    @GetMapping("/mock")
    @AccessLog(extractor = UrlParamExtractor.class)
    public Mono<String> mock(@RequestParam("p1") String p1) {
        System.out.println(">>> " + p1);
        return Mono.just(p1);
    }

    @PostMapping("/mock2")
    @AccessLog(extractor = BodyParamExtractor.class, receiver = ResponseBodyReceiver.class)
    public Mono<String> mock2(@RequestBody User body) {
        System.out.println(">>> " + body.toString());
        return Mono.just("111");
    }

    static class User {
        String name;

        public User() {
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        @Override
        public String toString() {
            return "User{" +
              "name='" + name + '\'' +
              '}';
        }
    }
}
